package com.sinocloud.springmvc.demo.controller;

import com.sinocloud.springmvc.demo.dao.UserDao;
import com.sinocloud.springmvc.demo.model.User;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.support.WebApplicationContextUtils;

@Controller
@RequestMapping("/welcome")
public class HelloController {

    @Resource(name = "userDao")
    private UserDao userDao;
    
    @RequestMapping(method = RequestMethod.GET)
    public String goToFolder(HttpServletRequest request, HttpSession session, ModelMap model) {
        String name = request.getParameter("name");
        model.addAttribute("message", "Spring  MVC 3.2.3");
        session.setAttribute("name", name);
        //ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
        //UserDao userDao = (UserDao) ctx.getBean("userDao");
        User user = userDao.queryById("1");
        System.out.println("userName:" + user.getName());
        return "folder/test";
    }

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    
}
